home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue66 / Clinic / PackageExpert.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2000-12-04  |  3.3 KB  |  147 lines

  1. unit PackageExpert;
  2.  
  3. interface
  4.  
  5. procedure Register;
  6.  
  7. implementation
  8.  
  9. uses
  10.   Dialogs, Classes, Menus, SysUtils, Forms, ExptIntf,
  11.   EditIntf, ToolIntf, Windows, Controls;
  12.  
  13. const
  14.   ExpertName = 'Pacakge Editor Locator';
  15.   ExpertAuthor = 'Oblong';
  16.   MenuBarItemCaption = '&Clinic';
  17.   MenuItemCaption = '&Show package editors';
  18.   MenuItemKey = VK_F2;
  19.   MenuItemShifts = [ssCtrl, ssAlt];
  20.  
  21. type
  22.   TPackageExpert = class(TIExpert)
  23.   private
  24.     //The menu bar item, and menu items that we will add in to app
  25.     FMenuBarItem,
  26.     FMenuItem: TIMenuItemIntf;
  27.   protected
  28.     //These are the event handlers of our new menu items
  29.     procedure MenuItemClick(Sender: TIMenuItemIntf);
  30.   public
  31.     constructor Create;
  32.     destructor Destroy; override;
  33.     function GetName:        string; override;
  34.     function GetComment:     string; override;
  35.     function GetAuthor:      string; override;
  36.     function GetPage:        string; override;
  37.     function GetGlyph:       HICON;  override;
  38.     function GetStyle: TExpertStyle; override;
  39.     function GetState: TExpertState; override;
  40.     function GetIDString:    string; override;
  41.     function GetMenuText:    string; override;
  42.     procedure Execute;               override;
  43.   end;
  44.  
  45. { TPackageExpert }
  46.  
  47. constructor TPackageExpert.Create;
  48. var
  49.   FMainmenu: TIMainMenuIntf;
  50. begin
  51.   inherited;
  52.   if Assigned(ToolServices) then
  53.   begin
  54.     FMainMenu := ToolServices.GetMainMenu;
  55.     if Assigned(FMainMenu) then
  56.       try
  57.         FMenuBarItem := FMainMenu.GetMenuItems.InsertItem(
  58.           FMainMenu.GetMenuItems.GetItemCount-1,
  59.           MenuBarItemCaption, '', '', 0, 0, 0, [mfEnabled, mfVisible], nil);
  60.         FMenuItem := FMenuBarItem.InsertItem(0,
  61.           MenuItemCaption, '', '', ShortCut(MenuItemKey, MenuItemShifts),
  62.           0, 0, [mfEnabled, mfVisible], MenuItemClick);
  63.       finally
  64.         FMainMenu.Free
  65.       end
  66.   end
  67. end;
  68.  
  69. destructor TPackageExpert.Destroy;
  70. begin
  71.   if Assigned(FMenuItem) then
  72.   begin
  73.     FMenuItem.DestroyMenuItem;
  74.     FMenuItem := nil
  75.   end;
  76.   if Assigned(FMenuBarItem) then
  77.   begin
  78.     FMenuBarItem.DestroyMenuItem;
  79.     FMenuBarItem := nil
  80.   end;
  81.   inherited;
  82. end;
  83.  
  84. procedure TPackageExpert.Execute;
  85. begin
  86. end;
  87.  
  88. function TPackageExpert.GetAuthor: string;
  89. begin
  90.   Result := ExpertAuthor;
  91. end;
  92.  
  93. function TPackageExpert.GetComment: string;
  94. begin
  95.   Result := '';
  96. end;
  97.  
  98. function TPackageExpert.GetGlyph: HICON;
  99. begin
  100.   Result := 0
  101. end;
  102.  
  103. function TPackageExpert.GetIDString: string;
  104. begin
  105.   Result := GetName;
  106. end;
  107.  
  108. function TPackageExpert.GetMenuText: string;
  109. begin
  110.   Result := '';
  111. end;
  112.  
  113. function TPackageExpert.GetName: string;
  114. begin
  115.   Result := ExpertName;
  116. end;
  117.  
  118. function TPackageExpert.GetPage: string;
  119. begin
  120.   Result := '';
  121. end;
  122.  
  123. function TPackageExpert.GetState: TExpertState;
  124. begin
  125.   Result := [esEnabled];
  126. end;
  127.  
  128. function TPackageExpert.GetStyle: TExpertStyle;
  129. begin
  130.   Result := esAddIn;
  131. end;
  132.  
  133. procedure TPackageExpert.MenuItemClick(Sender: TIMenuItemIntf);
  134. var
  135.   I: Integer;
  136. begin
  137.   for I := 0 to Screen.FormCount - 1 do
  138.     if CompareText(Screen.Forms[I].ClassName, 'TPackageEditorForm') = 0 then
  139.       Screen.Forms[I].BringToFront
  140. end;
  141.  
  142. procedure Register;
  143. begin
  144.   RegisterLibraryExpert(TPackageExpert.Create)
  145. end;
  146.  
  147. end.